# 棋盘大小
BOARD_SIZE = 17

# 初始化棋盘
def initialize_board():
    board = [[' ' for _ in range(BOARD_SIZE)] for _ in range(BOARD_SIZE)]
    # 初始化红色棋子
    for i in range(5):
        for j in range(5 - i):
            board[i][j + 6 + i] = 'R'
    # 初始化蓝色棋子
    for i in range(5):
        for j in range(5 - i):
            board[16 - i][j + 6 + i] = 'B'
    return board

# 打印棋盘
def print_board(board):
    for i, row in enumerate(board):
        print(' ' * (BOARD_SIZE - i), end='')
        for cell in row:
            print(cell, end=' ')
        print()

# 检查坐标是否在棋盘内
def is_valid_coordinate(x, y):
    return 0 <= x < BOARD_SIZE and 0 <= y < BOARD_SIZE

# 检查目标位置是否为空
def is_empty(board, x, y):
    return board[x][y] == ' '

# 检查是否可以移动（简单移动和单次跳）
def is_valid_move(board, from_x, from_y, to_x, to_y, player):
    piece = board[from_x][from_y]
    if piece != player:
        return False
    if not is_valid_coordinate(to_x, to_y) or not is_empty(board, to_x, to_y):
        return False
    # 简单移动
    dx = to_x - from_x
    dy = to_y - from_y
    if abs(dx) <= 1 and abs(dy) <= 1:
        return True
    # 单次跳
    if abs(dx) == 2 and abs(dy) == 2:
        mid_x = (from_x + to_x) // 2
        mid_y = (from_y + to_y) // 2
        return board[mid_x][mid_y] not in [' ', player]
    return False

# 移动棋子
def move_piece(board, from_x, from_y, to_x, to_y):
    piece = board[from_x][from_y]
    board[from_x][from_y] = ' '
    board[to_x][to_y] = piece
    return board

# 主游戏循环
def main():
    board = initialize_board()
    current_player = 'R'
    while True:
        print_board(board)
        print(f"Current player: {'Red' if current_player == 'R' else 'Blue'}")
        try:
            from_pos = input("Enter the position of the piece to move (e.g., 1 2): ").split()
            to_pos = input("Enter the destination position (e.g., 2 3): ").split()
            from_x, from_y = int(from_pos[0]), int(from_pos[1])
            to_x, to_y = int(to_pos[0]), int(to_pos[1])
            if is_valid_move(board, from_x, from_y, to_x, to_y, current_player):
                board = move_piece(board, from_x, from_y, to_x, to_y)
                current_player = 'B' if current_player == 'R' else 'R'
            else:
                print("Invalid move. Please try again.")
        except (ValueError, IndexError):
            print("Invalid input. Please enter valid positions.")

if __name__ == "__main__":
    main()